#include "comm.hpp"
#include "fifo.hpp"


int main()
{
    int shmid = GetShm();
    log(Debug,"create shm done");
    sleep(5);

    char *shadd = (char *)shmat(shmid, nullptr, 0);
    log(Debug,"attach shm done");

    int fd = open(FIFO_FILE, O_RDONLY);
    if(fd < 0)
    {
        log(Fatal,"open fail! %s",strerror(errno));
        exit(1);
    }

    char rd = 0;
    while (true)
    {
        int n = read(fd,&rd,sizeof(rd));
        if(n > 0) cout << "The signal is received. I can continue" << endl;
        else if(n == 0) exit(0);

        printf("%s", shadd);
        sleep(1);
    }

    return 0;
}